package server_commet;


import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
import files_handler.FileServlet;

/**
 * main function of the server, 
 * used to start the server
 * 
 * @author Yoav
 *
 */

public class Main {

	/**
	 * main function
	 * @param args main args 
	 */
	public static void main(String[] args) throws Exception {
		//create a server
	     Server server = new Server(9991);
	     
	     ContextHandlerCollection contexts = new ContextHandlerCollection();
	     
	     //create servlet context	     
	     ServletContextHandler  servletContext = new ServletContextHandler (server,"/servlet",ServletContextHandler.SESSIONS);	    

	     FileServlet fileServlet=new FileServlet();
	     //set servlet and mapping
	     servletContext.addServlet(new ServletHolder(fileServlet), "/AddUpdate");
	     servletContext.addServlet(new ServletHolder(fileServlet), "/Delete");
	     servletContext.addServlet(new ServletHolder(fileServlet), "/ChkExists");
	     servletContext.addServlet(new ServletHolder(fileServlet), "/Download");
	     servletContext.addServlet(new ServletHolder(fileServlet), "/Rename");
	     LinkClients linkClients=new LinkClients();
	     servletContext.addServlet(new ServletHolder(linkClients), "/link");
	     servletContext.addServlet(new ServletHolder(linkClients), "/update");
	     
	         
	     //set web app context
	     ContextHandler jspContext = new WebAppContext();
	     jspContext.setResourceBase("WebRoot/");
	     jspContext.setContextPath("/");	    
	        
	     //add contexts to server
	     contexts.addHandler(jspContext);
	     contexts.addHandler(servletContext);
	    
	     server.setHandler(contexts);
	     
	    //start server   
	     
	     server.start();
	     //jspContext.start();
	     server.join();	 
	     
	    }

}
